package org.springblade.modules.system.controller;

import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.annotations.ApiOperation;
import org.springblade.core.launch.constant.AppConstant;
import org.springblade.core.secure.BladeUser;
import org.springblade.core.tool.api.R;
import org.springblade.core.tool.utils.Func;
import org.springblade.modules.digitalization.service.IB01Service;
import org.springblade.modules.digitalization.vo.B01VO;
import org.springblade.modules.system.dto.DeptAssignOrgDTO;
import org.springblade.modules.system.service.IDeptService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RequestMapping(AppConstant.APPLICATION_SYSTEM_NAME + "/dept/assign")
@RestController
public class DeptAssignOrgController {

	@Autowired
	private IDeptService deptService;

	@Autowired
	private IB01Service b01Service;

	@GetMapping("/{deptId}")
	public R<List<String>> getAssignedOrg(@PathVariable String deptId) {
		List<String> orgIds = deptService.getAssignedOrg(deptId);
		return R.data(orgIds);
	}

	@PostMapping
	public R assignedOrg(@RequestBody DeptAssignOrgDTO deptAssignOrgDTO) {
		int status = deptService.assignedOrg(deptAssignOrgDTO);
		return R.data(status);
	}

	@GetMapping("/tree")
	public R<List<B01VO>> tree(String tenantId, BladeUser bladeUser) {
		List<Long> deptIds = Func.toLongList(bladeUser.getDeptId());
		List<B01VO> tree = b01Service.tree(Func.toStrWithEmpty(tenantId, bladeUser.getTenantId()), deptIds);
		return R.data(tree);
	}
}
